package com.example.dllo.baidumusic.main;
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.dllo.baidumusic.R;
import com.example.dllo.baidumusic.nettool.BaseActivity;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

/**
 * Created by dllo on 16/9/2.
 */
public class RegisterActivity extends BaseActivity {
    private EditText username;
    private EditText password;
    private Button regisrterOk;
    private BmobUser bmob;

    @Override

    protected int setLayout() {
        return R.layout.activity_register;
    }

    @Override
    protected void initView() {
        username = bindView(R.id.register_username);
        password = bindView(R.id.register_password);
        regisrterOk = bindView(R.id.register_ok);
        regisrterOk.setOnClickListener(this);

    }

    @Override
    protected void initData() {

    }


    @Override
    public void onClick(View v) {
        bmob = new BmobUser();
        bmob.setUsername(username.getText().toString());
        bmob.setPassword(password.getText().toString());
        bmob.signUp(new SaveListener<BmobUser>() {
            @Override
            public void done(BmobUser bmobUser, BmobException e) {
                if (e == null) {
                    Toast.makeText(RegisterActivity.this, "注册成功,在此登录", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(getApplication(), MeLoghActivity.class);
                    startActivity(intent);
                } else {
                    Log.d("RegisterActivity", e.toString() + "失败");
                }
            }
        });
    }
}
